<?php
date_default_timezone_set('PRC');
require_once dirname(__FILE__) . './models/keyword.php';

if( isset($_REQUEST["action"]) ){
	if( $_REQUEST["action"] == "submit" ){
		$post = new keyword();
		$post->date = time();
		$post->title =  $_REQUEST["title"];
		#$post->alt = $_REQUEST["content"];
		$post->save();
	}
	
	if( $_REQUEST["action"] == "delete" ){
		$post = keyword::find($_REQUEST["id"]);
		$post->delete();
	}	
}

?>

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<?php header("Content-type: text/html; charset=utf-8"); ?>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="libs\bootstrap-3.0.3-dist\dist\css\bootstrap.min.css">
	<style>
		.keywordlist ul {
			list-style:none;
			margin:0px;
			padding:0px;
		} 
		.keywordlist ul li {
			float:left; 
			padding:5px;
		} 
	</style>
  </head>
  <body>
	<div class="container"> 
		<a href="index.php" >进度</a>
		<a href="wanted.php">需求</a>
		<a href="keyword.php">关键字</a>
	</div>
    
	<div class="container" style="padding:15px;">
		<form action="keyword.php" method="post">
			<div class="form-group">
				<input class="form-control" name="title" placeholder="输入一枚关键字"></textarea>
			</div>
			
			<input type="submit" value="submit" class="btn btn-primary pull-right">
			<input type="hidden" name="action" value="submit">
		</form>
	</div>
	
	<div class="container keywordlist">
		<ul>
			<?php
			$wanteds = keyword::find('all');
			foreach ($wanteds as $key=>$node) { 
				$fmt_date = date('Y-m-d H:i:s', $node->date);
				$title = $node->title;
				$content = $node->alt;
				$id = $node->id;
			?>
			<li>
				<span class="label label-default" href="#">

					<?php echo $title; ?>
					<a href="keyword.php?action=delete&id=<?php echo $id; ?>"><i class="glyphicon glyphicon-remove"></i></a>
				</span>	
			</li>
			<?php } ?>
		</ul>	
	</div>
	
    <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <script src="libs\bootstrap-3.0.3-dist\dist\js\bootstrap.min.js"></script>
  </body>
</html>



